<?php
/**
 * Created by PhpStorm.
 * User: yangfan
 * Date: 2020/2/26
 * Time: 10:10 PM
 */

namespace App\BO\Product;

use App\Entities\ProductSkuEntity;
use App\Utils\Assert;

class ProductSkuInfoFactory
{
    /**
     * @param int $productSkuId
     * @return ProductSkuInfo
     * @throws \Exception
     */
    public static function getProductSkuInfo(int $productSkuId)
    {
        $productSkuEntity = ProductSkuEntity::find($productSkuId);
        Assert::notNull($productSkuEntity);

        $productBO = ProductBOFactory::getByProductIdAndCityId($productSkuEntity->getProductId(), $productSkuEntity->getCityId());
        Assert::notNull($productBO);

        $productSkuInfo = new ProductSkuInfo();
        $productSkuInfo->setProductId($productBO->getId());
        $productSkuInfo->setProductSkuId($productSkuEntity->getId());
        $productSkuInfo->setProductTitle($productBO->getTitle());
        $productSkuInfo->setOrderImage($productBO->getOrderImage());
        $productSkuInfo->setProductSkuTitle($productSkuEntity->getTitle());
        $productSkuInfo->setPrice($productSkuEntity->getPrice());
        $productSkuInfo->setOldPrice($productSkuEntity->getOldPrice());

        return $productSkuInfo;
    }
}
